﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LWH.ByteProtocol
{
    public class IndefiniteLengthProperty : SkeletalProperty
    {
        private Func<IndefiniteLengthProperty, int> mGetLengthDelegate;

        public IndefiniteLengthProperty(OwnerProperty ownerProperty, Func<IndefiniteLengthProperty, int> getLengthDelegate=null) : base(ownerProperty)
        {
            mGetLengthDelegate = getLengthDelegate;
        }

        override public int getLength()
        {
            if(mGetLengthDelegate!=null)
            {
                return mGetLengthDelegate(this);
            }
            return 0;
        }

        public Func<IndefiniteLengthProperty, int> GetLengthDelegate
        {
            get
            {
                return mGetLengthDelegate;
            }

            set
            {
                mGetLengthDelegate = value;
            }
        }
    }
}
